StringScanner.SkipToStringI Function

Syntax

Result_Flag as L = SkipToStringI as l(characters as c)

Arguments

Result_Flag

True if the string was found.

characters

The character string to search for. Case insensitive.

Description

Skip until text matching string (case insensitive) is found. Return true if successful.

Discussion

The <StringScanner>.SkipToStringI() function moves the offset to the beginning of of Find_Text. The offset does not move if it is already pointing to Find_Text.

Example

dim scanner as P
dim txt as C
txt = <<%text%
This is wonderful prose written
by a technical writer of note.
%text%
scanner = stringscanner.create(txt)
? scanner.SkipToStringI("writer")
= .T.
? scanner.GetToOffset()
= This is wonderful prose written
by a technical
? scanner.getremainder()
= writer of note.

The following example uses <StringScanner>.SkipToString()to count instances of a string in a text file. <StringScanner>.SkipToString()positions the offset pointer at the beginning of the text that it finds. Note how sc.ScanOver(1) moves the offset pointer just enough so that the next search will find a different instance of the search text.

dim sc as P
dim fbuffer as C
dim fname as C
dim count as N = 0
dim flag as L = .F.
fname = ui_get_file("Get File","c:\*.hhc")
fbuffer = file.to_string(fname)
sc = stringscanner.create(fbuffer)
flag = sc.SkipToString("FIND_ME")
while flag = .T.
    if (flag = .T.) then
        count = count + 1
    end if
    sc.ScanOver(1)
    flag = sc.SkipToString("FIND_ME")
end while
ui_msg_box("Count", "FIND_ME = " + count)

A comparison with OCCURSI() showed that a WHILE...END WHILE loop using <StringScanner>.SkipToString()(similar to the above script) was approximately 60 times faster.

See Also